<?php

namespace app\modules\admin\controllers;

use Qiniu\Auth;
use yii\web\Controller;

/**
 * Default controller for the `admin` module
 */
class DefaultController extends Controller
{
    /**
     * Renders the index view for the module
     * @return string
     */
    public function actionIndex()
    {
        $auth = new Auth(\Yii::$app->params['qiniu']['ak'], \Yii::$app->params['qiniu']['sk']);
        $token = $auth->uploadToken(\Yii::$app->params['qiniu']['bucket']);
        return $this->render('index', [
            'config' => [
                'baseURL' => '/',
                'qiniu' => [
                    'token' => $token,
                    'origin' => \Yii::$app->params['qiniu']['origin']
                ]
            ]
        ]);
    }

    public function actionLogout()
    {
        \Yii::$app->admin->logout();
        \Yii::$app->admin->loginRequired();
    }
}
